﻿using System;
using System.Text.RegularExpressions;

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            //1、生成一个随机整型数组，长度是10，内容是1~10，数组内容不重复。
            Sb();
            Console.WriteLine("--------");
            //2、生成0 - 5之间的随机小数，保留两位小数。
            Sb1();
            Console.WriteLine("-------");
            //3、生成4 - 7之间的随机小数，保留两位小数。
            Sb2();
            Console.WriteLine("--------");
            //4、用户输入邮箱，请验证其合法性。
            Sb3();
            Console.WriteLine("--------");
            //5、用户输入手机号码，请验证其合法性。



            Console.ReadKey();
        }
        static void Sb() 
        {
            Random ran = new Random();
            int[] arr = new int[10];
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = ran.Next(1,11);
            }
            Boolean bol = true;
            while (bol)
            {
                Array.Sort(arr);
                int num = 0;
                for (int i = 0; i < 9; i++)
                {
                    if (arr[i] != arr[i+1])
                    {
                        num++;
                    }
                    else
                    {
                        arr[i + 1] = ran.Next(1,11);
                    }
                    if (num==9)
                    {
                        bol = false;
                        foreach (int item in arr)
                        {
                            Console.Write(item +" ");
                        }
                    }
                }

            }
            Console.WriteLine();
        }
        static void Sb1() 
        {
            Random ran = new Random();
            double a = ran.Next(0, 5);
            string b = ran.NextDouble().ToString("f2");
            double d = Convert.ToDouble(b);
            double c = a + d;
            Console.WriteLine(c);
        }
        static void Sb2() 
        {
            Random ran = new Random();
            double a = ran.Next(4, 7);
            string b = ran.NextDouble().ToString("f2");
            double d = Convert.ToDouble(b);
            double c = a + d;
            Console.WriteLine(c);
        }
        static void Sb3()
        {
            while (true)
            {
                Regex regex = new Regex(@"^(\w)+(\.\w)*@(\w)+((\.\w+))+$");
                Console.WriteLine("请输入");
                string input = Console.ReadLine();
                //Console.WriteLine(regex.IsMatch(input));
                if (regex.IsMatch(input))
                {
                    Console.WriteLine("正确");
                }
                else
                {
                    Console.WriteLine("错误");
                }
            }

        }
        static void Sb4()
        {
            Console.WriteLine("请输入你的手机号码");
            string a = Console.ReadLine();
            if (Regex.IsMatch(a, @"^(\+86)?1[3-9](\d){9}$"))
            {
                Console.WriteLine("正确");
            }
            else
            {
                Console.WriteLine("错误");
            }
        }
    }
}
